package com.hk.enums;

import lombok.Getter;

/**
 * @author huangkun
 * @date 2024/12/11 20:45
 */
@Getter
public enum UserRoleEnum {

    USER(1, "user", "普通用户"),
    ADMIN(0, "admin", "管理员"),
    ;
    private final int code;
    private final String value;
    private final String Description;

    UserRoleEnum(int coe, String value, String description) {
        this.code = coe;
        this.value = value;
        this.Description = description;
    }

    /**
     * 根据code获取
     *
     * @param code
     * @return
     */
    public static UserRoleEnum getEnumByCode(int code) {
        for (UserRoleEnum roleEnum : UserRoleEnum.values()) {
            if (roleEnum.code == code) {
                return roleEnum;
            }
        }
        return null;
    }

    /**
     * 根据value获取
     *
     * @param value
     * @return
     */
    public static UserRoleEnum getEnumByValue(String value) {
        for (UserRoleEnum roleEnum : UserRoleEnum.values()) {
            if (roleEnum.value.equals(value)) {
                return roleEnum;
            }
        }
        return null;
    }


}
